const utils = require('common.js');
//const utils = require('/storage/emulated/0/脚本/common.js');

var storage = storages.create("init");
var vedios= parseInt(storage.get("音恋文章"));

var appname = "音恋"
var cs= storage.get(appname+"初始");
var sx= storage.get(appname+"上限");

if(cs>=sx){
    toastLog(appname+"达到阅读上限");
    exit();
}else{
    storage.put(appname+"初始",cs+vedios);
    log(storage.get(appname+"初始"));
}

initParam={
    appName:"音恋",
    totalNewsReaded : 0,//已经阅读的新闻条数
    totalNewsOneTime : 50,//一次性阅读多少条新闻
    loopTimeToFindNews : 5,//找了多少次新闻找不到会退出
    indexBtnText: "", //其他页面挑到首页的按钮文字，重要！
    indexFlagText:"关注",
    readallText:"展开全文",

    tanchuang:"imgClose",
    timeAwardText : "领取",//时段奖励关键字

    lastVedioText:"",//上一次新闻标题
    totalVedioReaded : 0,//已经阅读的新闻条数
    totalVedioOneTime : 50,//一次性阅读多少条新闻
    loopTimeToFindVedio : 20,//找了多少次新闻找不到会退出
    stanchuang:"弹窗id",
    indexBtnTexts: "首页", //其他页面挑到首页的按钮文字，重要！
    indexFlagTexts : "iv_like",//首页特有的标志id，重要！

    news:0,
    vedio:vedios,
    hdsj:12,
    newssx:"首页",
    vediosx:"首页",
};

utils.wakeUp(); 
utils.clears();
utils.launch(initParam.appName);
sleep(4000);
utils.UITextBoundsClick("知道了");
utils.UITextBoundsClick("首页");

sleep(3000)
utils.UITextBoundsClick("我的");

sleep(5000)
var gx1 = text("进入 任务").findOnce()
if(gx1){
    toastLog("点击任务");
    click(gx1.bounds().centerX(),gx1.bounds().centerY());
    sleep(4000)
    if(textContains("任务").findOnce()){
        sleep(1000)
    }else{

    swipe(device.width / 2, device.height*0.2,  device.width / 2, device.height*0.8, 1500);
    sleep(7000)
    }
    for(var j=0;j<9;j++){ 
        sleep(1000)
    log("xxx")
    var gx1 = text("去完成").findOnce()
    if(gx1){
        click(gx1.bounds().centerX(),gx1.bounds().centerY());
        sleep(3000)
        toastLog("观看视频");
        var gx1 = text("点击观看").findOnce()
        if(gx1){
            toastLog("点击观看");
            click(gx1.bounds().centerX(),gx1.bounds().centerY());
            sleep(3000)
        }
       
        sleep(65000)
        back()
        utils.UIIDBoundsClick("tt_video_ad_close");
        sleep(2000)
        var gx1 = text("确认").findOnce()
        if(gx1){
            toastLog("点击确定");
            click(gx1.bounds().centerX(),gx1.bounds().centerY());
            sleep(5000)
        }
    }
    utils.UIIDBoundsClick("tt_video_ad_close");
    utils.UITextBoundsClick("确认");
    if(descContains("下载").findOnce()){
        var gb = className("android.widget.ImageView").depth(5).findOnce()
        if(gb){
            click(gb.bounds().centerX(),gb.bounds().centerY());
            log("关闭")
            sleep(1500);
        }
    }
    if(textContains("下载").findOnce()){
        var gb = className("android.widget.ImageView").depth(5).findOnce()
        if(gb){
            click(gb.bounds().centerX(),gb.bounds().centerY());
            log("关闭")
            sleep(1500);
        }
    }
    if(textContains("点击打开").findOnce()){
        var gb = className("android.widget.ImageView").depth(5).findOnce()
        if(gb){
            click(gb.bounds().centerX(),gb.bounds().centerY());
            log("关闭")
            sleep(1500);
        }
    }
    }
    swipe(device.width / 2, device.height/1.2,  device.width / 2, device.height-device.height/1.05, 1500);
}

for(var j=0;j<3;j++){
    swipe(device.width / 2, device.height*0.2,  device.width / 2, device.height*0.8, 1500);
    sleep(1000)
}
var gx1 = desc("未完成").findOnce()
if(gx1){
    toastLog("领取奖励");
    click(gx1.bounds().centerX(),gx1.bounds().centerY());
    sleep(65000)
    utils.UITextBoundsClick("确定");
    back();
}
var gx1 = text("未完成").findOnce()
if(gx1){
    toastLog("领取奖励");
    click(gx1.bounds().centerX(),gx1.bounds().centerY());
    sleep(65000)
    utils.UITextBoundsClick("确定");
    back();
}
var gx1 = desc("领取奖励").findOnce()
if(gx1){
    toastLog("领取奖励");
    click(gx1.bounds().centerX(),gx1.bounds().centerY());
    sleep(65000)
    utils.UITextBoundsClick("确定");
    back();
}
var gx1 = text("领取奖励").findOnce()
if(gx1){
    toastLog("领取奖励");
    click(gx1.bounds().centerX(),gx1.bounds().centerY());
    sleep(65000)
    utils.UITextBoundsClick("确定");
    back();
}
//阅读新闻
function readvedios(seconds){

        //滑动阅读新闻
        for(var i = 0 ;i < 1 ;i++){
            var tt = random(10000,20000);
            sleep(tt);
        }

}


